package com.jqr.activity.roomsqlitedemo;

import android.content.Context;

import androidx.room.Room;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

import com.jqr.activity.roomsqlitedemo.data.JqrDatabase;
import com.jqr.activity.roomsqlitedemo.data.UserDao;
import com.jqr.activity.roomsqlitedemo.data.UserRepository;
import com.jqr.activity.roomsqlitedemo.model.User;

import java.util.List;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    private JqrDatabase jqrDatabase;
    private UserDao userDao;

    private UserRepository userRepository;
    @Before
    public void setup(){
        Context context= ApplicationProvider.getApplicationContext();
        jqrDatabase= Room.inMemoryDatabaseBuilder(context,JqrDatabase.class).build();
        userDao=jqrDatabase.userDao();

        userRepository=new UserRepository(userDao,context);
    }
    @Test
    public void useAppContext() {
        // Context of the app under test.
        User user=new User();
        user.uid=1;
        user.firstName="wu";
        user.lastName="zongbo";

        userRepository.Add(user);


        List<User> users=userRepository.getAll();

        System.out.println(users.get(0).firstName);

    }
}